package com.middlegroup.common.model;//
import com.middlegroup.common.exception.ErrorCode;

import java.io.Serializable;

/**
 * @author pc
 */
public class ResponseEntity implements Serializable {
    private static final long serialVersionUID = -720807478055084231L;
    public static final String STATUS_OK = "1";
    public static final String STATUS_FAIL = "0";
    private String status;
    private String error;
    private String msg;
    private Object data;

    public static void populateByErrorCode(ResponseEntity entity, String errorCode, String errorMsg) {
        errorCode = null != errorCode && !errorCode.isEmpty()?errorCode:"E00090000";
        errorMsg = null != errorMsg && !errorMsg.isEmpty()?errorMsg: ErrorCode.getMsg(errorCode);
        if("E00000000".equals(errorCode)) {
            entity.setStatus("1");
        } else {
            entity.setStatus("0");
        }

        entity.setError(errorCode);
        entity.setMsg(errorMsg);
    }

    public static void populateByErrorCode(ResponseEntity entity, String errorCode) {
        populateByErrorCode(entity, errorCode, (String)null);
    }

    public static ResponseEntity fromErrorCode(String errorCode) {
        ResponseEntity ret = new ResponseEntity();
        populateByErrorCode(ret, errorCode);
        return ret;
    }

    public ResponseEntity() {
    }

    public ResponseEntity(String status) {
        this.status = status;
    }

    public ResponseEntity(String status, String error) {
        this.status = status;
        this.error = error;
    }

    public ResponseEntity(String status, Object data) {
        this.status = status;
        this.data = data;
    }

    public ResponseEntity(String status, Object data, int currentPage, int pageCount, int pageSize, int recordsTotal) {
        this.status = status;
        this.data = data;
    }

    public ResponseEntity(String status, Object data, int pageCount) {
        this.status = status;
        this.data = data;
    }

    public ResponseEntity(String status, String error, String msg, Object data) {
        this.status = status;
        this.error = error;
        this.msg = msg;
        this.data = data;
    }

    public ResponseEntity setStatus(String status) {
        this.status = status;
        return this;
    }

    public ResponseEntity setError(String error) {
        this.error = error;
        return this;
    }

    public ResponseEntity setMsg(String msg) {
        this.msg = msg;
        return this;
    }

    public String getStatus() {
        return this.status;
    }

    public String getError() {
        return this.error;
    }

    public String getMsg() {
        return this.msg;
    }

    public Object getData() {
        return this.data;
    }


    public void setData(Object data) {
        this.data = data;
    }





    @Override
    public boolean equals(Object o) {
        if(o == this) {
            return true;
        } else if(!(o instanceof ResponseEntity)) {
            return false;
        } else {
            ResponseEntity other = (ResponseEntity)o;
            if(!other.canEqual(this)) {
                return false;
            } else {
                label119: {
                    String this$status = this.getStatus();
                    String other$status = other.getStatus();
                    if(this$status == null) {
                        if(other$status == null) {
                            break label119;
                        }
                    } else if(this$status.equals(other$status)) {
                        break label119;
                    }

                    return false;
                }

                String this$error = this.getError();
                String other$error = other.getError();
                if(this$error == null) {
                    if(other$error != null) {
                        return false;
                    }
                } else if(!this$error.equals(other$error)) {
                    return false;
                }

                label105: {
                    String this$msg = this.getMsg();
                    String other$msg = other.getMsg();
                    if(this$msg == null) {
                        if(other$msg == null) {
                            break label105;
                        }
                    } else if(this$msg.equals(other$msg)) {
                        break label105;
                    }

                    return false;
                }

                Object this$data = this.getData();
                Object other$data = other.getData();
                if(this$data == null) {
                    if(other$data != null) {
                        return false;
                    }
                } else if(!this$data.equals(other$data)) {
                    return false;
                }

                return true;
            }
        }
    }

    public boolean canEqual(Object other) {
        return other instanceof ResponseEntity;
    }

    @Override
    public int hashCode() {
        boolean PRIME = true;
        byte result = 1;
        String $status = this.getStatus();
        int result1 = result * 59 + ($status == null?0:$status.hashCode());
        String $error = this.getError();
        result1 = result1 * 59 + ($error == null?0:$error.hashCode());
        String $msg = this.getMsg();
        result1 = result1 * 59 + ($msg == null?0:$msg.hashCode());
        Object $data = this.getData();
        result1 = result1 * 59 + ($data == null?0:$data.hashCode());
        return result1;
    }

    @Override
    public String toString() {
        return "ResponseEntity(super=" + super.toString() + ", status=" + this.getStatus() + ", error=" + this.getError() + ", msg=" + this.getMsg() + ", data=" + this.getData() + ")";
    }
}
